package com.example;

import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;

public class SmsContentObserver extends ContentObserver {

    public static final String TAG = "SmsContentObserver";

    public static final Uri targetUri = Uri.parse("content://sms/raw");

    private Handler handler;

    public SmsContentObserver(Handler handler) {
        super(handler);
        this.handler = handler;
    }

    public Handler getHandler() {
        return handler;
    }

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    @Override
    public void onChange(boolean selfChange, Uri uri) {
        if (uri.compareTo(targetUri) == 0) {
            handler.obtainMessage().sendToTarget();
        }
    }
}
